﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Activities;
using System.Activities.Statements;
using System.Windows.Forms;
using PrinterBudi.Persistence;

namespace PrinterBudi.Desktop
{
    public partial class FormLogin : Form
    {
        #region disable close button
        private const int CP_NOCLOSE_BUTTON = 0x200;
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams myCp = base.CreateParams;
                myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
                return myCp;
            }
        }
        #endregion

        public FormLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            string user = tb_phonenumber.Text;
            string pass = tb_password.Text;

            IDictionary<string, object> output = WorkflowInvoker.Invoke(new WFLogin()
                {
                    InUser = user,
                    InPass = pass
                });

            bool status = (bool)output["OutStatus"];

            if (status == true)
            {
                FormMain frm = new FormMain(PBEmployeeModel.Read(user));
                this.Hide();

                frm.ShowDialog();

                this.Show();
                this.Activate();
            }
            else
                MessageBox.Show("Wrong Phone Number or Password!");
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
